﻿#pragma once

#include "IUnderWaterComAlgorithm.h"

class UnderWaterComAlogrithm : public IUnderWaterComAlgorithm {
public:

	void IPP_Va_Init();
    void SF_IPP_Va_Init();          //短帧初始化函数
    void MASS_Init();
    void QPSK_IPP_Va_Init();

    float SC_FDE_DECODE(float* data1, float* data2, float* data3, float* data4, Ipp32fc* Signal_DataEqu, const char* BinaryData,
        Ipp32fc* Syn_DataCachePrmy_1_COPY,
        Ipp32fc* Syn_DataCachePrmy_2_COPY,
        Ipp32fc* Syn_DataCachePrmy_3_COPY,
        Ipp32fc* Syn_DataCachePrmy_4_COPY);

    //短帧解码函数
    float SF_SC_FDE_DECODE(float* data1, float* data2, float* data3, float* data4, Ipp32fc* Signal_DataEqu, const char* BinaryData,
        Ipp32fc* SF_Syn_DataCachePrmy_1_COPY,
        Ipp32fc* SF_Syn_DataCachePrmy_2_COPY,
        Ipp32fc* SF_Syn_DataCachePrmy_3_COPY,
        Ipp32fc* SF_Syn_DataCachePrmy_4_COPY);

    void MASS_DECODE(float* data, float* channel_length, Ipp8u* Mass_BitsDecoded, Ipp32f* Syn2_CorrCur_Padded_Copy , int* synFlag);

    float SC_FDE_DECODE_6K8K(float* data1, float* data2, float* data3, float* data4, Ipp32fc* Signal_DataEqu, const char* BinaryData,
        Ipp32fc* Syn_DataCachePrmy_1_COPY,
        Ipp32fc* Syn_DataCachePrmy_2_COPY,
        Ipp32fc* Syn_DataCachePrmy_3_COPY,
        Ipp32fc* Syn_DataCachePrmy_4_COPY);

    float SF_SC_FDE_DECODE_6K8K(float* data1, float* data2, float* data3, float* data4, Ipp32fc* Signal_DataEqu, const char* BinaryData,
        Ipp32fc* SF_Syn_DataCachePrmy_1_COPY,
        Ipp32fc* SF_Syn_DataCachePrmy_2_COPY,
        Ipp32fc* SF_Syn_DataCachePrmy_3_COPY,
        Ipp32fc* SF_Syn_DataCachePrmy_4_COPY);

    void MASS_DECODE_6K8K(float* data, float* channel_length, Ipp8u* Mass_BitsDecoded, Ipp32f* Syn2_CorrCur_Padded_Copy, int* synFlag);

    void My_GenerateQPSKSignal_Wrapper(
        // 输入参数 - 常量部分
        Ipp32f fs,                    // 采样频率
        Ipp32f f0_1,                  // 载波频率
        Ipp32f f0_2,                  // 载波频率
        Ipp32f R_s1,                  // 有效符号速率
        Ipp32f alpha_1,               // 滚降系数
        Ipp32s M,                     // 调制阶数
        Ipp32s bitnum_per,            // 每符号比特数
        Ipp32f Sym_time,              // 有效符号持续时间
        Ipp32s Numburst,              // 突发数量
        Ipp32s Numblock_perburst,     // 每突发块数

        // 输入参数 - 线性调频信号
        Ipp32f* sig_syn_LFM_1,        // 线性调频信号
        Ipp32f* sig_syn_LFM_2,        // 线性调频信号
        Ipp32s syn_length,            // 线性调频信号长度

        Ipp32f* p_1,                 // 根升余弦滤波器系数
        Ipp32s p_1_length,            // 根升余弦滤波器长度



        const char* filename, int N, int& data_size, Ipp32f* signal_send_1, Ipp32f* signal_send_2, int* output_length);


    void MDFE_DECODE(float* data1, float* data2, float* data3, float* data4,
        float* data5, float* data6, float* data7, float* data8,
        float* data9, float* data10, float* data11, float* data12,
        float* data13, float* data14, float* data15, float* data16,

        Ipp32fc* Syn_DataCachePrmy_COPY,
        Ipp32fc* va_Syn_FIRCoe_SC_BANDPASS_QPSK, Ipp32s va_Syn_FIRLen_BANDPASS_QPSK,
        Ipp32fc* va_Syn_RefCopySam, Ipp32fc* va_Syn_RefCopyAll,
        Ipp32u va_MQPSK_f0,
        int va_n1, int va_n2, float va_Delta, float va_Lambda, float va_PLL1, float va_PLL2,
        Ipp32u va_MaxCacheFrameCnt_QPSK, Ipp32f va_Syn_Threshold_QPSK, QPSK_Channel* channels, Ipp8u* va_BitsAftDemaapping,
        bool* decode_completed_flag , bool decode_enable_flag, Ipp32fc* x_zheng_without_train_seq);

    float My_Calculate_BER_AND_SAVE_IMG(Ipp8u* BitsAftDemaapping_1, Ipp8u* BitsAftDemaapping_2,
        const char* file_name, Ipp8u va_MQPSK_N, Ipp8u va_MQPSK_data_length);

    void QPSK_Channel_Init(QPSK_Channel* channel);
    void QPSK_Channel_Free(QPSK_Channel* channel);
    
    void MyLoadCharData(const char* filename, char* data, int length);

    void        My_ippsZero_32fc(Ipp32fc* pDst, int len);
    void        My_ippsZero_32f(Ipp32f* pDst, int len);
    void        My_ippsZero_8u(Ipp8u* pDst, int len);
    Ipp8u*      My_ippsMalloc_8u(int len);
    Ipp32fc*    My_ippsMalloc_32fc(int len);
    Ipp32f*     My_ippsMalloc_32f(int len);
    void        My_ippsFree(void* ptr);

private:
	bool GetExePath(char* filepath, const int& max_length);

private:

    Ipp8u* Syn_StepCnt_1 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* Syn_DataCacheCnt_1 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* Syn_DataCache_1 = ippsMalloc_32fc(g_Syn_BufCnt * 30);
    Ipp32fc* Syn_DataCachePrmy_1 = ippsMalloc_32fc(g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* Sig_blk_1 = ippsMalloc_32fc(g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* Syn_SigIn_1 = ippsMalloc_32f(g_Syn_BufCnt);//每次输入的信号
    Ipp32f* Syn_SigRec_1 = ippsMalloc_32f(g_InfoSamPointTotalSyn);
    Ipp16u MaxNum_1 = MaxCacheFrameCnt;
    Ipp8u   Syn_Flag_1 = 0;//同步标志位，失败(0)/成功(1)
    int Syn_PosFirst_1 = -1;
    int  Syn_FlagFirst_1 = 0;

    Ipp8u* Syn_StepCnt_2 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* Syn_DataCacheCnt_2 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* Syn_DataCache_2 = ippsMalloc_32fc(g_Syn_BufCnt * 30);
    Ipp32fc* Syn_DataCachePrmy_2 = ippsMalloc_32fc(g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* Sig_blk_2 = ippsMalloc_32fc(g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* Syn_SigIn_2 = ippsMalloc_32f(g_Syn_BufCnt);//每次输入的信号
    Ipp32f* Syn_SigRec_2 = ippsMalloc_32f(g_InfoSamPointTotalSyn);
    Ipp16u MaxNum_2 = MaxCacheFrameCnt;
    Ipp8u   Syn_Flag_2 = 0;//同步标志位，失败(0)/成功(1)
    int Syn_PosFirst_2 = -1;
    int  Syn_FlagFirst_2 = 0;


    Ipp8u* Syn_StepCnt_3 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* Syn_DataCacheCnt_3 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* Syn_DataCache_3 = ippsMalloc_32fc(g_Syn_BufCnt * 30);
    Ipp32fc* Syn_DataCachePrmy_3 = ippsMalloc_32fc(g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* Sig_blk_3 = ippsMalloc_32fc(g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* Syn_SigIn_3 = ippsMalloc_32f(g_Syn_BufCnt);//每次输入的信号
    Ipp32f* Syn_SigRec_3 = ippsMalloc_32f(g_InfoSamPointTotalSyn);
    Ipp16u MaxNum_3 = MaxCacheFrameCnt;
    Ipp8u   Syn_Flag_3 = 0;//同步标志位，失败(0)/成功(1)
    int Syn_PosFirst_3 = -1;
    int  Syn_FlagFirst_3 = 0;


    Ipp8u* Syn_StepCnt_4 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* Syn_DataCacheCnt_4 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* Syn_DataCache_4 = ippsMalloc_32fc(g_Syn_BufCnt * 30);
    Ipp32fc* Syn_DataCachePrmy_4 = ippsMalloc_32fc(g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* Sig_blk_4 = ippsMalloc_32fc(g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* Syn_SigIn_4 = ippsMalloc_32f(g_Syn_BufCnt);//每次输入的信号
    Ipp32f* Syn_SigRec_4 = ippsMalloc_32f(g_InfoSamPointTotalSyn);
    Ipp16u MaxNum_4 = MaxCacheFrameCnt;
    Ipp8u   Syn_Flag_4 = 0;//同步标志位，失败(0)/成功(1)
    int Syn_PosFirst_4 = -1;
    int  Syn_FlagFirst_4 = 0;


    // 短帧全局变量声明 - 信道1
    Ipp8u* SF_Syn_StepCnt_1 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* SF_Syn_DataCacheCnt_1 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* SF_Syn_DataCache_1 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 30);
    Ipp32fc* SF_Syn_DataCachePrmy_1 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* SF_Sig_blk_1 = ippsMalloc_32fc(SF_g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* SF_Syn_SigIn_1 = ippsMalloc_32f(SF_g_Syn_BufCnt);//每次输入的信号
    Ipp32f* SF_Syn_SigRec_1 = ippsMalloc_32f(SF_g_InfoSamPointTotalSyn);
    Ipp16u SF_MaxNum_1 = SF_MaxCacheFrameCnt;
    Ipp8u SF_Syn_Flag_1 = 0;//同步标志位，失败(0)/成功(1)
    int SF_Syn_PosFirst_1 = -1;
    int SF_Syn_FlagFirst_1 = 0;

    // 短帧全局变量声明 - 信道2
    Ipp8u* SF_Syn_StepCnt_2 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* SF_Syn_DataCacheCnt_2 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* SF_Syn_DataCache_2 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 40);
    Ipp32fc* SF_Syn_DataCachePrmy_2 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 40);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* SF_Sig_blk_2 = ippsMalloc_32fc(SF_g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* SF_Syn_SigIn_2 = ippsMalloc_32f(SF_g_Syn_BufCnt);//每次输入的信号
    Ipp32f* SF_Syn_SigRec_2 = ippsMalloc_32f(SF_g_InfoSamPointTotalSyn);
    Ipp16u SF_MaxNum_2 = SF_MaxCacheFrameCnt;
    Ipp8u SF_Syn_Flag_2 = 0;//同步标志位，失败(0)/成功(1)
    int SF_Syn_PosFirst_2 = -1;
    int SF_Syn_FlagFirst_2 = 0;

    // 短帧全局变量声明 - 信道3
    Ipp8u* SF_Syn_StepCnt_3 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* SF_Syn_DataCacheCnt_3 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* SF_Syn_DataCache_3 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 40);
    Ipp32fc* SF_Syn_DataCachePrmy_3 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 40);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* SF_Sig_blk_3 = ippsMalloc_32fc(SF_g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* SF_Syn_SigIn_3 = ippsMalloc_32f(SF_g_Syn_BufCnt);//每次输入的信号
    Ipp32f* SF_Syn_SigRec_3 = ippsMalloc_32f(SF_g_InfoSamPointTotalSyn);
    Ipp16u SF_MaxNum_3 = SF_MaxCacheFrameCnt;
    Ipp8u SF_Syn_Flag_3 = 0;//同步标志位，失败(0)/成功(1)
    int SF_Syn_PosFirst_3 = -1;
    int SF_Syn_FlagFirst_3 = 0;

    // 短帧全局变量声明 - 信道4
    Ipp8u* SF_Syn_StepCnt_4 = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* SF_Syn_DataCacheCnt_4 = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* SF_Syn_DataCache_4 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 30);
    Ipp32fc* SF_Syn_DataCachePrmy_4 = ippsMalloc_32fc(SF_g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* SF_Sig_blk_4 = ippsMalloc_32fc(SF_g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* SF_Syn_SigIn_4 = ippsMalloc_32f(SF_g_Syn_BufCnt);//每次输入的信号
    Ipp32f* SF_Syn_SigRec_4 = ippsMalloc_32f(SF_g_InfoSamPointTotalSyn);
    Ipp16u SF_MaxNum_4 = SF_MaxCacheFrameCnt;
    Ipp8u SF_Syn_Flag_4 = 0;//同步标志位，失败(0)/成功(1)
    int SF_Syn_PosFirst_4 = -1;
    int SF_Syn_FlagFirst_4 = 0;

    //扩频全局变量
    Ipp8u* Syn_StepCnt_MASS = ippsMalloc_8u(sizeof(Ipp8u));//切换同步函数工作在粗同步(0)/缓存(1)/细同步(2)三个模式状态，初始化为0
    Ipp8u* Syn_DataCacheCnt_MASS = ippsMalloc_8u(sizeof(Ipp8u));//缓存模式下缓存帧计数，初始化为0;
    Ipp32fc* Syn_DataCache_MASS = ippsMalloc_32fc(MA_g_Syn_BufCnt * 30);
    Ipp32fc* Syn_DataCachePrmy_MASS = ippsMalloc_32fc(MA_g_Syn_BufCnt * 30);//原始信号的缓存数组，为了解决频域细同步对同步信号与数据信号间隔有要求的问题
    Ipp32fc* Sig_blk_MASS = ippsMalloc_32fc(MA_g_Syn_NFFT_RAW);//用于抽样同步，每次数据传递的外部数组,初始化为0
    Ipp32f* Syn_SigIn_MASS = ippsMalloc_32f(MA_g_Syn_BufCnt);//每次输入的信号
    Ipp32f* Syn_SigRec_MASS = ippsMalloc_32f(MA_g_InfoSamPointTotalSyn);
    Ipp8u   Syn_Flag_MASS = 0;//同步标志位，失败(0)/成功(1)
    Ipp16u MaxNum_MASS = MaxCacheFrameCnt;
    int Syn_PosFirst_MASS = -1;
    int  Syn_FlagFirst_MASS = 0;

    //以下是QPSK全局变量
    

    //QPSK_Channel channels_1[MQPSK_channel_num];
    //QPSK_Channel channels_2[MQPSK_channel_num];

    // Channel 1
    Ipp32f* Syn_SigIn_1_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 2
    Ipp32f* Syn_SigIn_2_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 3
    Ipp32f* Syn_SigIn_3_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 4
    Ipp32f* Syn_SigIn_4_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 5
    Ipp32f* Syn_SigIn_5_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 6
    Ipp32f* Syn_SigIn_6_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 7
    Ipp32f* Syn_SigIn_7_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 8
    Ipp32f* Syn_SigIn_8_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);
    // Channel 9
    Ipp32f* Syn_SigIn_9_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 10
    Ipp32f* Syn_SigIn_10_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 11
    Ipp32f* Syn_SigIn_11_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 12
    Ipp32f* Syn_SigIn_12_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 13
    Ipp32f* Syn_SigIn_13_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 14
    Ipp32f* Syn_SigIn_14_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 15
    Ipp32f* Syn_SigIn_15_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);

    // Channel 16
    Ipp32f* Syn_SigIn_16_QPSK = ippsMalloc_32f(QPSK_g_Syn_BufCnt);
};


